HolographContract
Contracts • API
Holograph SDK Reference / Contracts / HolographContract
Class: HolographContract
Remarks
Holograph is the primary entry point for all users and developers. A single, universal address across all blockchains will enable developers an easy way to interact with the protocol’s features. Holograph keeps references for all current Registry, Factory, and Bridge implementations. Furthermore, it allows for single interface management of the underlying protocol.
Holograph provides a reference to the name and ID of all supported blockchains. Additionally, it:
- enables custom contract logic that is chain-dependent
- frees developers from having to query and monitor the blockchain
Extends
Constructors
new HolographContract(parentLogger)
new HolographContract(
parentLogger
?):HolographContract
Parameters
• parentLogger?: HolographLogger
Returns
Overrides
HolographBaseContract
.constructor
Source
packages/sdk/src/contracts/holograph.contract.ts:24
Properties
_abi
protected
readonly
_abi:Abi
Inherited from
Source
packages/sdk/src/contracts/holograph-base.contract.ts:43
_addresses
protected
readonly
_addresses:Record
<number
,0x${string}
> ={}
The record of addresses per chainId.
Inherited from
HolographBaseContract
._addresses
Source
packages/sdk/src/contracts/holograph-base.contract.ts:36
_config
protected
readonly
_config:Config
Inherited from
Source
packages/sdk/src/contracts/holograph-base.contract.ts:41
_logger
protected
_logger:HolographLogger
Inherited from
Source
packages/sdk/src/contracts/holograph-base.contract.ts:42
_providers
protected
readonly
_providers:Providers
Inherited from
HolographBaseContract
._providers
Source
packages/sdk/src/contracts/holograph-base.contract.ts:37
_walletManager?
protected
optional
_walletManager:HolographWalletManager
Inherited from
HolographBaseContract
._walletManager
Source
packages/sdk/src/contracts/holograph-base.contract.ts:38
networks
readonly
networks:Network
[]
The list of networks in which the contract was instantiated.
Inherited from
HolographBaseContract
.networks
Source
packages/sdk/src/contracts/holograph-base.contract.ts:34
Methods
_callContractFunction()
protected
_callContractFunction<TAbi
>(__namedParameters
):Promise
<string
|string
[]>
Type parameters
• TAbi extends Abi
Parameters
• __namedParameters: CallContractFunctionArgs
<TAbi
>
Returns
Promise
<string
| string
[]>
Inherited from
HolographBaseContract
._callContractFunction
Source
packages/sdk/src/contracts/holograph-base.contract.ts:147
_estimateContractGas()
protected
_estimateContractGas<TAbi
>(__namedParameters
):Promise
<bigint
>
Type parameters
• TAbi extends Abi
Parameters
• __namedParameters: EstimateContractGasArgs
<TAbi
>
Returns
Promise
<bigint
>
Inherited from
HolographBaseContract
._estimateContractGas
Source
packages/sdk/src/contracts/holograph-base.contract.ts:106
_getContractFunction()
private
_getContractFunction(__namedParameters
):Promise
<string
|string
[]>
Parameters
• __namedParameters: GetContractFunctionArgs
<[object
, object
, object
, object
, object
]>
Returns
Promise
<string
| string
[]>
Source
packages/sdk/src/contracts/holograph.contract.ts:46
_readContract()
protected
_readContract<TAbi
>(__namedParameters
):Promise
<unknown
>
Type parameters
• TAbi extends Abi
Parameters
• __namedParameters: ReadContractArgs
<TAbi
>
Returns
Promise
<unknown
>
Inherited from
HolographBaseContract
._readContract
Source
packages/sdk/src/contracts/holograph-base.contract.ts:138
_simulateContract()
protected
_simulateContract<TAbi
>(__namedParameters
):Promise
<any
>
Type parameters
• TAbi extends Abi
Parameters
• __namedParameters: SimulateContractArgs
<TAbi
>
Returns
Promise
<any
>
Inherited from
HolographBaseContract
._simulateContract
Source
packages/sdk/src/contracts/holograph-base.contract.ts:72
_writeContract()
protected
_writeContract<TAbi
>(__namedParameters
):Promise
<0x${string}
>
Type parameters
• TAbi extends Abi
Parameters
• __namedParameters: WriteContractArgs
<TAbi
>
Returns
Promise
<0x${string}
>
Inherited from
HolographBaseContract
._writeContract
Source
packages/sdk/src/contracts/holograph-base.contract.ts:122
getAddress()
readonly
getAddress(chainId
?):0x${string}
Get the Holograph contract address according to environment and chainId module.
Parameters
• chainId?: string
| number
The chain id of the network to get the result from.
Returns
0x${string}
The Holograph contract address in the provided network.
Source
packages/sdk/src/contracts/holograph.contract.ts:42
getBridge()
readonly
getBridge(chainId
):Promise
<string
|string
[]>
Get the address of the Holograph Bridge module. Used for bridging holographable assets cross-chain.
Parameters
• chainId: number
The chain id of the network to get the result from.
Returns
Promise
<string
| string
[]>
The HolographBridge contract address in the provided network.
Source
packages/sdk/src/contracts/holograph.contract.ts:63
getBridgeByNetworks()
readonly
getBridgeByNetworks(chainIds
?):Promise
<HolographByNetworksResponse
>
Get the address of the Holograph Bridge module. Used for bridging holographable assets cross-chain.
Parameters
• chainIds?: number
[]
The list of network chainIds to get the results from, if nothing is provided the default are the networks defined in the config.
Returns
Promise
<HolographByNetworksResponse
>
The HolographBridge contract address per network.
Source
packages/sdk/src/contracts/holograph.contract.ts:74
getChainId()
readonly
getChainId(chainId
):Promise
<string
|string
[]>
Get the chain ID that the Protocol was deployed on. Useful for checking if/when a hard fork occurs.
Parameters
• chainId: number
The chain id of the network to get the result from.
Returns
Promise
<string
| string
[]>
The chainId in the provided network.
Source
packages/sdk/src/contracts/holograph.contract.ts:93
getChainIdByNetworks()
readonly
getChainIdByNetworks(chainIds
?):Promise
<HolographByNetworksResponse
>
Get the chain ID that the Protocol was deployed on. Useful for checking if/when a hard fork occurs.
Parameters
• chainIds?: number
[]
The list of network chainIds to get the results from, if nothing is provided the default are the networks defined in the config.
Returns
Promise
<HolographByNetworksResponse
>
The chainIds per network.
Source
packages/sdk/src/contracts/holograph.contract.ts:105
getClientByChainId()
readonly
getClientByChainId(chainId
):Promise
<object
>
Get the Viem client for a certain network.
Parameters
• chainId: number
The chain id of the network to get the result from.
Returns
Promise
<object
>
The Viem client object.
account
account:
undefined
The Account of the Client.
batch?
optional
batch:object
Flags for batch settings.
batch.multicall?
optional
multicall:boolean
| { batchSize?: number | undefined; wait?: number | undefined; }Toggle to enable
eth_call
multicall aggregation.cacheTime
cacheTime:
number
Time (in ms) that cached data will remain in memory.
call()
call: (
parameters
) =>Promise
<CallReturnType
>Executes a new message call immediately without submitting a transaction to the network.
- Docs: https://viem.sh/docs/actions/public/call
- JSON-RPC Methods:
eth_call
Parameters
• parameters:
CallParameters
<undefined
|Chain
>Returns
Promise
<CallReturnType
>The call data. CallReturnType
Example
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const data = await client.call({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})chain
chain:
undefined
|Chain
Chain for the client.
createBlockFilter()
createBlockFilter: () =>
Promise
<object
>Creates a Filter to listen for new block hashes that can be used with
getFilterChanges
.
- Docs: https://viem.sh/docs/actions/public/createBlockFilter
- JSON-RPC Methods:
eth_newBlockFilter
Returns
Promise
<object
>Filter. CreateBlockFilterReturnType
id
id:
0x${string}
request
request:
EIP1193RequestFn
<readonly [object
,object
,object
]>type
type:
"block"
Example
import { createPublicClient, createBlockFilter, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const filter = await createBlockFilter(client)
// { id: "0x345a6572337856574a76364e457a4366", type: 'block' }createContractEventFilter()
createContractEventFilter: <
TAbi
,TEventName
,TArgs
,TStrict
,TFromBlock
,TToBlock
>(args
) =>Promise
<CreateContractEventFilterReturnType
<TAbi
,TEventName
,TArgs
,TStrict
,TFromBlock
,TToBlock
>>Creates a Filter to retrieve event logs that can be used with
getFilterChanges
orgetFilterLogs
.Type parameters
• TAbi extends readonly
unknown
[] |Abi
• TEventName extends
undefined
|string
• TArgs extends
undefined
| readonlyunknown
[] |Record
<string
,unknown
>• TStrict extends
undefined
|boolean
=undefined
• TFromBlock extends
undefined
|bigint
|BlockTag
=undefined
• TToBlock extends
undefined
|bigint
|BlockTag
=undefined
Parameters
• args:
CreateContractEventFilterParameters
<TAbi
,TEventName
,TArgs
,TStrict
,TFromBlock
,TToBlock
>CreateContractEventFilterParameters
Returns
Promise
<CreateContractEventFilterReturnType
<TAbi
,TEventName
,TArgs
,TStrict
,TFromBlock
,TToBlock
>>
Filter
. CreateContractEventFilterReturnTypeExample
import { createPublicClient, http, parseAbi } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const filter = await client.createContractEventFilter({
abi: parseAbi(['event Transfer(address indexed, address indexed, uint256)']),
})createEventFilter()
createEventFilter: <
TAbiEvent
,TAbiEvents
,TStrict
,TFromBlock
,TToBlock
,_EventName
,_Args
>(args
?) =>Promise
<{ [K in keyof Filter<"event", TAbiEvents, _EventName, _Args, TStrict, TFromBlock, TToBlock>]: Filter<"event", TAbiEvents, ... 4 more ..., TToBlock>[K]; }>Creates a
Filter
to listen for new events that can be used withgetFilterChanges
.
- Docs: https://viem.sh/docs/actions/public/createEventFilter
- JSON-RPC Methods:
eth_newFilter
Type parameters
• TAbiEvent extends
undefined
|AbiEvent
=undefined
• TAbiEvents extends
undefined
| readonlyunknown
[] | readonlyAbiEvent
[] =TAbiEvent
extendsAbiEvent
? [TAbiEvent
] :undefined
• TStrict extends
undefined
|boolean
=undefined
• TFromBlock extends
undefined
|bigint
|BlockTag
=undefined
• TToBlock extends
undefined
|bigint
|BlockTag
=undefined
• _EventName extends
undefined
|string
=MaybeAbiEventName
<TAbiEvent
>• _Args extends
undefined
| readonlyunknown
[] |Record
<string
,unknown
> =undefined
Parameters
• args?:
CreateEventFilterParameters
<TAbiEvent
,TAbiEvents
,TStrict
,TFromBlock
,TToBlock
,_EventName
,_Args
>CreateEventFilterParameters
Returns
Promise
<{ [K in keyof Filter<"event", TAbiEvents, _EventName, _Args, TStrict, TFromBlock, TToBlock>]: Filter<"event", TAbiEvents, ... 4 more ..., TToBlock>[K]; }>
Filter
. CreateEventFilterReturnTypeExample
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const filter = await client.createEventFilter({
address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
})createPendingTransactionFilter()
createPendingTransactionFilter: () =>
Promise
<object
>Creates a Filter to listen for new pending transaction hashes that can be used with
getFilterChanges
.
- Docs: https://viem.sh/docs/actions/public/createPendingTransactionFilter
- JSON-RPC Methods:
eth_newPendingTransactionFilter
Returns
Promise
<object
>
Filter
. CreateBlockFilterReturnTypeid
id:
0x${string}
request
request:
EIP1193RequestFn
<readonly [object
,object
,object
]>type
type:
"transaction"
Example
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const filter = await client.createPendingTransactionFilter()
// { id: "0x345a6572337856574a76364e457a4366", type: 'transaction' }estimateContractGas()
estimateContractGas: <
TChain
,abi
,functionName
,args
>(args
) =>Promise
<bigint
>Estimates the gas required to successfully execute a contract write function call.
Type parameters
• TChain extends
undefined
|Chain
• abi extends readonly
unknown
[] |Abi
• functionName extends
string
• args extends
unknown
Parameters
• args:
EstimateContractGasParameters
<abi
,functionName
,args
,TChain
>EstimateContractGasParameters
Returns
Promise
<bigint
>The gas estimate (in wei). EstimateContractGasReturnType
Remarks
Internally, uses a Public Client to call the
estimateGas
action with ABI-encodeddata
.Example
import { createPublicClient, http, parseAbi } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const gas = await client.estimateContractGas({
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: parseAbi(['function mint() public']),
functionName: 'mint',
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
})estimateFeesPerGas()
estimateFeesPerGas: <
TChainOverride
,TType
>(args
?) =>Promise
<EstimateFeesPerGasReturnType
>Returns an estimate for the fees per gas for a transaction to be included in the next block.
Type parameters
• TChainOverride extends
undefined
|Chain
=undefined
• TType extends
FeeValuesType
="eip1559"
Parameters
• args?:
EstimateFeesPerGasParameters
<undefined
|Chain
,TChainOverride
,TType
>Returns
Promise
<EstimateFeesPerGasReturnType
>An estimate (in wei) for the fees per gas. EstimateFeesPerGasReturnType
Example
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const maxPriorityFeePerGas = await client.estimateFeesPerGas()
// { maxFeePerGas: ..., maxPriorityFeePerGas: ... }estimateGas()
estimateGas: (
args
) =>Promise
<bigint
>Estimates the gas necessary to complete a transaction without submitting it to the network.
- Docs: https://viem.sh/docs/actions/public/estimateGas
- JSON-RPC Methods:
eth_estimateGas
Parameters
• args:
EstimateGasParameters
<undefined
|Chain
>EstimateGasParameters
Returns
Promise
<bigint
>The gas estimate (in wei). EstimateGasReturnType
Example
import { createPublicClient, http, parseEther } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const gasEstimate = await client.estimateGas({
account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1'),
})estimateMaxPriorityFeePerGas()
estimateMaxPriorityFeePerGas: <
TChainOverride
>(args
?) =>Promise
<bigint
>Returns an estimate for the max priority fee per gas (in wei) for a transaction to be included in the next block.
Type parameters
• TChainOverride extends
undefined
|Chain
=undefined
Parameters
• args?
• args.chain?:
null
|TChainOverride
Returns
Promise
<bigint
>An estimate (in wei) for the max priority fee per gas. EstimateMaxPriorityFeePerGasReturnType
Example
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const maxPriorityFeePerGas = await client.estimateMaxPriorityFeePerGas()
// 10000000nextend()
extend: <
client
>(fn
) =>Client
<Transport
,undefined
|Chain
,undefined
,PublicRpcSchema
, { [K in keyof client]: client[K]; } &PublicActions
<Transport
,undefined
|Chain
>>Type parameters
• client extends { [x: string]: unknown; account?: undefined; batch?: undefined; cacheTime?: undefined; chain?: undefined; key?: undefined; name?: undefined; pollingInterval?: undefined; request?: undefined; transport?: undefined; type?: undefined; uid?: undefined; } &
Partial
<ExtendableProtectedActions
<Transport
,undefined
|Chain
,undefined
>>Parameters
• fn
Returns
Client
<Transport
,undefined
|Chain
,undefined
,PublicRpcSchema
, { [K in keyof client]: client[K]; } &PublicActions
<Transport
,undefined
|Chain
>>getBalance()
getBalance: (
args
) =>Promise
<bigint
>Returns the balance of an address in wei.
- Docs: https://viem.sh/docs/actions/public/getBalance
- JSON-RPC Methods:
eth_getBalance
Parameters
• args:
GetBalanceParameters
GetBalanceParameters
Returns
Promise
<bigint
>The balance of the address in wei. GetBalanceReturnType
Remarks
You can convert the balance to ether units with
formatEther
.const balance = await getBalance(client, {
address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
blockTag: 'safe'
})
const balanceAsEther = formatEther(balance)
// "6.942"Example
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const balance = await client.getBalance({
address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
})
// 10000000000000000000000n (wei)getBlock()
getBlock: <
TIncludeTransactions
,TBlockTag
>(args
?) =>Promise
<{ number: TBlockTag extends "pending" ? null : bigint; gasLimit: bigint; hash: TBlockTag extends "pending" ? null : `0x${string}`; nonce: TBlockTag extends "pending" ? null : `0x${string}`; ... 21 more ...; transactions: TIncludeTransactions extends true ? ({ ...; } | ... 2 more ... | { ...; })[] : `0x${string}`[]; }>Returns information about a block at a block number, hash, or tag.
- Docs: https://viem.sh/docs/actions/public/getBlock
- Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/blocks/fetching-blocks
- JSON-RPC Methods:
- Calls
eth_getBlockByNumber
forblockNumber
&blockTag
.- Calls
eth_getBlockByHash
forblockHash
.Type parameters
• TIncludeTransactions extends
boolean
=false
• TBlockTag extends
BlockTag
="latest"
Parameters
• args?:
GetBlockParameters
<TIncludeTransactions
,TBlockTag
>GetBlockParameters
Returns
Promise
<{ number: TBlockTag extends "pending" ? null : bigint; gasLimit: bigint; hash: TBlockTag extends "pending" ? null : `0x${string}`; nonce: TBlockTag extends "pending" ? null : `0x${string}`; ... 21 more ...; transactions: TIncludeTransactions extends true ? ({ ...; } | ... 2 more ... | { ...; })[] : `0x${string}`[]; }>Information about the block. GetBlockReturnType
Example
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const block = await client.getBlock()getBlockNumber()
getBlockNumber: (
args
?) =>Promise
<bigint
>Returns the number of the most recent block seen.
- Docs: https://viem.sh/docs/actions/public/getBlockNumber
- Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/blocks/fetching-blocks
- JSON-RPC Methods:
eth_blockNumber
Parameters
• args?:
GetBlockNumberParameters
GetBlockNumberParameters
Returns
Promise
<bigint
>The number of the block. GetBlockNumberReturnType
Example
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const blockNumber = await client.getBlockNumber()
// 69420ngetBlockTransactionCount()
getBlockTransactionCount: (
args
?) =>Promise
<number
>Returns the number of Transactions at a block number, hash, or tag.
- Docs: https://viem.sh/docs/actions/public/getBlockTransactionCount
- JSON-RPC Methods:
- Calls
eth_getBlockTransactionCountByNumber
forblockNumber
&blockTag
.- Calls
eth_getBlockTransactionCountByHash
forblockHash
.Parameters
• args?:
GetBlockTransactionCountParameters
GetBlockTransactionCountParameters
Returns
Promise
<number
>The block transaction count. GetBlockTransactionCountReturnType
Example
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const count = await client.getBlockTransactionCount()getBytecode()
getBytecode: (
args
) =>Promise
<GetBytecodeReturnType
>Retrieves the bytecode at an address.
- Docs: https://viem.sh/docs/contract/getBytecode
- JSON-RPC Methods:
eth_getCode
Parameters
• args:
GetBytecodeParameters
GetBytecodeParameters
Returns
Promise
<GetBytecodeReturnType
>The contract's bytecode. GetBytecodeReturnType
Example
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const code = await client.getBytecode({
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
})getChainId()
getChainId: () =>
Promise
<number
>Returns the chain ID associated with the current network.
- Docs: https://viem.sh/docs/actions/public/getChainId
- JSON-RPC Methods:
eth_chainId
Returns
Promise
<number
>The current chain ID. GetChainIdReturnType
Example
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const chainId = await client.getChainId()
// 1getContractEvents()
getContractEvents: <
abi
,eventName
,strict
,fromBlock
,toBlock
>(args
) =>Promise
<GetContractEventsReturnType
<abi
,eventName
,strict
,fromBlock
,toBlock
>>Returns a list of event logs emitted by a contract.
- Docs: https://viem.sh/docs/actions/public/getContractEvents
- JSON-RPC Methods:
eth_getLogs
Type parameters
• abi extends readonly
unknown
[] |Abi
• eventName extends
undefined
|string
=undefined
• strict extends
undefined
|boolean
=undefined
• fromBlock extends
undefined
|bigint
|BlockTag
=undefined
• toBlock extends
undefined
|bigint
|BlockTag
=undefined
Parameters
• args:
GetContractEventsParameters
<abi
,eventName
,strict
,fromBlock
,toBlock
>Returns
Promise
<GetContractEventsReturnType
<abi
,eventName
,strict
,fromBlock
,toBlock
>>A list of event logs. GetContractEventsReturnType
Example
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
import { wagmiAbi } from './abi'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const logs = await client.getContractEvents(client, {
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
eventName: 'Transfer'
})getEnsAddress()
getEnsAddress: (
args
) =>Promise
<GetEnsAddressReturnType
>Gets address for ENS name.
- Docs: https://viem.sh/docs/ens/actions/getEnsAddress
- Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens
Parameters
• args: { blockNumber?: bigint | undefined; blockTag?: BlockTag | undefined; coinType?: number | undefined; gatewayUrls?: string[] | undefined; name: string; strict?: boolean | undefined; universalResolverAddress?: `0x${string}` | undefined; }
GetEnsAddressParameters
Returns
Promise
<GetEnsAddressReturnType
>Address for ENS name or
null
if not found. GetEnsAddressReturnTypeRemarks
Calls
resolve(bytes, bytes)
on ENS Universal Resolver Contract.Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to normalize ENS names with UTS-46 normalization before passing them to
getEnsAddress
. You can use the built-innormalize
function for this.Example
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
import { normalize } from 'viem/ens'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const ensAddress = await client.getEnsAddress({
name: normalize('wevm.eth'),
})
// '0xd2135CfB216b74109775236E36d4b433F1DF507B'getEnsAvatar()
getEnsAvatar: (
args
) =>Promise
<GetEnsAvatarReturnType
>Gets the avatar of an ENS name.
- Docs: https://viem.sh/docs/ens/actions/getEnsAvatar
- Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens
Parameters
• args: { name: string; blockNumber?: bigint | undefined; blockTag?: BlockTag | undefined; gatewayUrls?: string[] | undefined; strict?: boolean | undefined; universalResolverAddress?: `0x${string}` | undefined; assetGatewayUrls?: AssetGatewayUrls | undefined; }
GetEnsAvatarParameters
Returns
Promise
<GetEnsAvatarReturnType
>Avatar URI or
null
if not found. GetEnsAvatarReturnTypeRemarks
Calls
getEnsText
withkey
set to'avatar'
.Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to normalize ENS names with UTS-46 normalization before passing them to
getEnsAddress
. You can use the built-innormalize
function for this.Example
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
import { normalize } from 'viem/ens'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const ensAvatar = await client.getEnsAvatar({
name: normalize('wevm.eth'),
})
// 'https://ipfs.io/ipfs/Qma8mnp6xV3J2cRNf3mTth5C8nV11CAnceVinc3y8jSbio'getEnsName()
getEnsName: (
args
) =>Promise
<GetEnsNameReturnType
>Gets primary name for specified address.
- Docs: https://viem.sh/docs/ens/actions/getEnsName
- Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens
Parameters
• args: { blockNumber?: bigint | undefined; blockTag?: BlockTag | undefined; address: `0x${string}`; gatewayUrls?: string[] | undefined; strict?: boolean | undefined; universalResolverAddress?: `0x${string}` | undefined; }
GetEnsNameParameters
Returns
Promise
<GetEnsNameReturnType
>Name or
null
if not found. GetEnsNameReturnTypeRemarks
Calls
reverse(bytes)
on ENS Universal Resolver Contract to "reverse resolve" the address to the primary ENS name.Example
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const ensName = await client.getEnsName({
address: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
})
// 'wevm.eth'getEnsResolver()
getEnsResolver: (
args
) =>Promise
<0x${string}
>Gets resolver for ENS name.
- Docs: https://viem.sh/docs/ens/actions/getEnsResolver
- Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens
Parameters
• args: { blockNumber?: bigint | undefined; blockTag?: BlockTag | undefined; name: string; universalResolverAddress?: `0x${string}` | undefined; }
GetEnsResolverParameters
Returns
Promise
<0x${string}
>Address for ENS resolver. GetEnsResolverReturnType
Remarks
Calls
findResolver(bytes)
on ENS Universal Resolver Contract to retrieve the resolver of an ENS name.Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to normalize ENS names with UTS-46 normalization before passing them to
getEnsAddress
. You can use the built-innormalize
function for this.Example
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
import { normalize } from 'viem/ens'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const resolverAddress = await client.getEnsResolver({
name: normalize('wevm.eth'),
})
// '0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41'getEnsText()
getEnsText: (
args
) =>Promise
<GetEnsTextReturnType
>Gets a text record for specified ENS name.
- Docs: https://viem.sh/docs/ens/actions/getEnsResolver
- Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens
Parameters
• args: { blockNumber?: bigint | undefined; blockTag?: BlockTag | undefined; name: string; gatewayUrls?: string[] | undefined; key: string; strict?: boolean | undefined; universalResolverAddress?: `0x${string}` | undefined; }
GetEnsTextParameters
Returns
Promise
<GetEnsTextReturnType
>Address for ENS resolver. GetEnsTextReturnType
Remarks
Calls
resolve(bytes, bytes)
on ENS Universal Resolver Contract.Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to normalize ENS names with UTS-46 normalization before passing them to
getEnsAddress
. You can use the built-innormalize
function for this.Example
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
import { normalize } from 'viem/ens'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const twitterRecord = await client.getEnsText({
name: normalize('wevm.eth'),
key: 'com.twitter',
})
// 'wagmi_sh'getFeeHistory()
getFeeHistory: (
args
) =>Promise
<GetFeeHistoryReturnType
>Returns a collection of historical gas information.
- Docs: https://viem.sh/docs/actions/public/getFeeHistory
- JSON-RPC Methods:
eth_feeHistory
Parameters
• args:
GetFeeHistoryParameters
GetFeeHistoryParameters
Returns
Promise
<GetFeeHistoryReturnType
>The gas estimate (in wei). GetFeeHistoryReturnType
Example
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const feeHistory = await client.getFeeHistory({
blockCount: 4,
rewardPercentiles: [25, 75],
})getFilterChanges()
getFilterChanges: <
TFilterType
,TAbi
,TEventName
,TStrict
,TFromBlock
,TToBlock
>(args
) =>Promise
<GetFilterChangesReturnType
<TFilterType
,TAbi
,TEventName
,TStrict
,TFromBlock
,TToBlock
>>Returns a list of logs or hashes based on a Filter since the last time it was called.
- Docs: https://viem.sh/docs/actions/public/getFilterChanges
- JSON-RPC Methods:
eth_getFilterChanges
Type parameters
• TFilterType extends
FilterType
• TAbi extends
undefined
| readonlyunknown
[] |Abi
• TEventName extends
undefined
|string
• TStrict extends
undefined
|boolean
=undefined
• TFromBlock extends
undefined
|bigint
|BlockTag
=undefined
• TToBlock extends
undefined
|bigint
|BlockTag
=undefined
Parameters
• args:
GetFilterChangesParameters
<TFilterType
,TAbi
,TEventName
,TStrict
,TFromBlock
,TToBlock
>GetFilterChangesParameters
Returns
Promise
<GetFilterChangesReturnType
<TFilterType
,TAbi
,TEventName
,TStrict
,TFromBlock
,TToBlock
>>Logs or hashes. GetFilterChangesReturnType
Remarks
A Filter can be created from the following actions:
Depending on the type of filter, the return value will be different:
- If the filter was created with
createContractEventFilter
orcreateEventFilter
, it returns a list of logs.- If the filter was created with
createPendingTransactionFilter
, it returns a list of transaction hashes.- If the filter was created with
createBlockFilter
, it returns a list of block hashes.Example
// Blocks
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const filter = await client.createBlockFilter()
const hashes = await client.getFilterChanges({ filter })Example
// Contract Events
import { createPublicClient, http, parseAbi } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const filter = await client.createContractEventFilter({
address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
abi: parseAbi(['event Transfer(address indexed, address indexed, uint256)']),
eventName: 'Transfer',
})
const logs = await client.getFilterChanges({ filter })Example
// Raw Events
import { createPublicClient, http, parseAbiItem } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const filter = await client.createEventFilter({
address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
event: parseAbiItem('event Transfer(address indexed, address indexed, uint256)'),
})
const logs = await client.getFilterChanges({ filter })Example
// Transactions
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const filter = await client.createPendingTransactionFilter()
const hashes = await client.getFilterChanges({ filter })getFilterLogs()
getFilterLogs: <
TAbi
,TEventName
,TStrict
,TFromBlock
,TToBlock
>(args
) =>Promise
<GetFilterLogsReturnType
<TAbi
,TEventName
,TStrict
,TFromBlock
,TToBlock
>>Returns a list of event logs since the filter was created.
- Docs: https://viem.sh/docs/actions/public/getFilterLogs
- JSON-RPC Methods:
eth_getFilterLogs
Type parameters
• TAbi extends
undefined
| readonlyunknown
[] |Abi
• TEventName extends
undefined
|string
• TStrict extends
undefined
|boolean
=undefined
• TFromBlock extends
undefined
|bigint
|BlockTag
=undefined
• TToBlock extends
undefined
|bigint
|BlockTag
=undefined
Parameters
• args:
GetFilterLogsParameters
<TAbi
,TEventName
,TStrict
,TFromBlock
,TToBlock
>GetFilterLogsParameters
Returns
Promise
<GetFilterLogsReturnType
<TAbi
,TEventName
,TStrict
,TFromBlock
,TToBlock
>>A list of event logs. GetFilterLogsReturnType
Remarks
getFilterLogs
is only compatible with event filters.Example
import { createPublicClient, http, parseAbiItem } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const filter = await client.createEventFilter({
address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
event: parseAbiItem('event Transfer(address indexed, address indexed, uint256)'),
})
const logs = await client.getFilterLogs({ filter })getGasPrice()
getGasPrice: () =>
Promise
<bigint
>Returns the current price of gas (in wei).
- Docs: https://viem.sh/docs/actions/public/getGasPrice
- JSON-RPC Methods:
eth_gasPrice
Returns
Promise
<bigint
>The gas price (in wei). GetGasPriceReturnType
Example
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const gasPrice = await client.getGasPrice()getLogs()
getLogs: <
TAbiEvent
,TAbiEvents
,TStrict
,TFromBlock
,TToBlock
>(args
?) =>Promise
<GetLogsReturnType
<TAbiEvent
,TAbiEvents
,TStrict
,TFromBlock
,TToBlock
>>Returns a list of event logs matching the provided parameters.
- Docs: https://viem.sh/docs/actions/public/getLogs
- Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/filters-and-logs/event-logs
- JSON-RPC Methods:
eth_getLogs
Type parameters
• TAbiEvent extends
undefined
|AbiEvent
=undefined